import requests
from bs4 import BeautifulSoup
import re
import csv
# url = 'http://www.woniuxy.com/note/782'
#
# html = requests.get(url=url)

# with open('22.html','w',encoding='utf-8') as f:
#     f.write(html.text)
# print(html.text)

# bs = BeautifulSoup(open('11.html',encoding='utf-8'),'lxml')
#
# next_url = bs.find_all(text="下一页")[0].find_parent().attrs.get('href')
# print(next_url)
# content = bs.find_all(class_ = "col-lg-12 col-md-12 col-sm-12 col-xs-12 article-list box")
# for content_url in content:
#     print(content_url('a')[0].attrs.get('href'))



bs = BeautifulSoup(open('22.html',encoding='utf-8'),'lxml')
# # bs = BeautifulSoup(html.text,'lxml')
# title = bs.find_all(class_ = "col-lg-10 col-md-10 col-sm-10 col-xs-10 title")[0].string.strip()
# print(title)
info = bs.find_all(class_ = "col-lg-12 col-md-12 col-sm-12 col-xs-12 info")
data = info[0].string.strip()
print(data)
print(type(data))
# data = '作者：管理员   类型：学院动态   类别：资讯   日期：2021-10-12   阅读：87 次   消耗积分：0 分'
print(re.findall(r'(\d{4}-\d{2}-\d{2})\s',data))
print(re.findall(r'(\d+)\s次',data))
# date_num = info[0].string.strip().find("日期：")
# read_num = info[0].string.strip().find("阅读：")
# end_num = info[0].string.strip().find("消耗积分：")
# # print(info[0].string.strip())
# # print(date_num)
# date = info[0].string.strip()[date_num+3:read_num].strip()
# print(date)
# read = info[0].string.strip()[read_num+3:end_num-4].strip()
# print(read)
# data = {
#     "标题": title,
#     "日期": date,
#     "阅读次数": read
# }
# data2 = {
#     "标题": "222",
#     "日期": "222",
#     "阅读次数": "222"
# }
# datas = []
# header = ['标题','日期','阅读次数']
# datas.append(data)
# datas.append(data2)
# with open('1111.csv', 'a', newline='', encoding='utf-8') as f:
#     writer = csv.DictWriter(f, fieldnames=header) # 提前预览列名，当下面代码写入数据时，会将其一一对应。
#     writer.writeheader() # 写入列名
#     writer.writerows(datas) # 写入数据
# print("数据已经写入成功！！！")

# dic = {
#     "11":"11",
#     "22":"22"
# }
# dic2 = dict()
# print(isinstance(dic,dict))

